package com.sugon.controller.analyse;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevStatusLiveRecordEntity;
import com.sugon.service.DevStatusLiveRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备状态实时记录表，一台设备对应一条状态记录Controller
 *
 * @author sugon
 * @date 2020-12-23 11:42:55
 */
@Controller
@RequestMapping("devstatusliverecord")
public class DevStatusLiveRecordController {
    @Autowired
    private DevStatusLiveRecordService devStatusLiveRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevStatusLiveRecordEntity> devStatusLiveRecordList = devStatusLiveRecordService.queryList(query);
        int total = devStatusLiveRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devStatusLiveRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevStatusLiveRecordEntity devStatusLiveRecord = devStatusLiveRecordService.queryObject(id);

        return R.ok().put("devStatusLiveRecord", devStatusLiveRecord);
    }

    /**
     * 保存
     */
    @AutoLog("设备状态实时记录表，一台设备对应一条状态记录--保存")
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody DevStatusLiveRecordEntity devStatusLiveRecord) {
        devStatusLiveRecordService.save(devStatusLiveRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("设备状态实时记录表，一台设备对应一条状态记录--修改")
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody DevStatusLiveRecordEntity devStatusLiveRecord) {
        devStatusLiveRecordService.update(devStatusLiveRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("设备状态实时记录表，一台设备对应一条状态记录--删除")
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devStatusLiveRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevStatusLiveRecordEntity> list = devStatusLiveRecordService.queryList(params);

        return R.ok().put("list", list);
    }
}
